package com.hmdp.utils;


import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Slf4j
public class LoginInterceptor  implements HandlerInterceptor {
   @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
      log.debug(">>>>>>>>>LoginInterceptor 拦截器 判断是否需要拦截");
      log.debug("查看 ThreadLocal是否有用户");
      if(UserHolder.getUser() == null){
           log.debug("ThreadLocal没有 用户的信息， 拦截器   拦截 <<<<<<<<<<<<<< ");
           response.setStatus(401);
           return false;
      }
      log.debug("ThreadLocal 有用户的信息, 放行<<<<<<<<<<<<<<<<<");
      return true;
    }
}
